package com.ophiux.oop;

public class Test {

    public static void main(String[] args) {
        Vehicle bus = new Bus("公交车");
        bus.getVehicleName();

        Car car = new Car("小汽车");
//        car.getVehicleName();
        car.getVehicleName("小汽车2");
        System.out.println();

        show(new Bus("公交车3"));
        show(new Car("小汽车3"));
    }

    /**
     * 多态存在的三个必要条件
     * 继承
     * 重写
     * 父类引用指向子类对象：Parent p = new Child();
     */
    public static void show(Vehicle vehicle){
        if(vehicle instanceof Bus){
            Bus bus = (Bus) vehicle;
            bus.getVehicleName();
        }else if(vehicle instanceof Car){
            Car car = (Car) vehicle;
            car.getVehicleName();
        }
    }
}
